package com.woniuxy.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

@Configuration
public class RedisConfig {

    @Bean("rt")
    public <T> RedisTemplate<String, T> createRedisTemplate(RedisConnectionFactory connectionFactory) {
        RedisTemplate<String, T> rt = new RedisTemplate<>();

        rt.setKeySerializer(RedisSerializer.string());
        rt.setValueSerializer(RedisSerializer.json());

        rt.setHashKeySerializer(RedisSerializer.json());
        rt.setHashValueSerializer(RedisSerializer.json());

        rt.setConnectionFactory(connectionFactory);

        rt.afterPropertiesSet();
        return rt;
    }
}
